package com.miniot.pest.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.miniot.business.base.BaseController;
import com.miniot.business.base.R;
import com.miniot.pest.entity.EquipmentDetail;
import com.miniot.pest.service.EquipmentDetailService;
import com.miniot.pest.vo.EquipmentDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 出入库管理表
 *
 * @author zzq
 * @date 2023-10-20 09:45:17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/equipmentdetail" )
@Api(value = "识别内容表(后台)", tags = "识别内容表-后台接口")
public class EquipmentDetailController extends BaseController {

    private final EquipmentDetailService equipmentDetailService;

    /**
    * 分页查询
    * @param currentPage 当前页数
    * @param pageSize 每页数据量
    * @param equipmentDetail 查询条件
    * @return 查询结果
    */
    @GetMapping("/listPage")
    @ApiOperation(value = "分页查询", notes = "传入分页信息与查询条件")
    public R<Page<EquipmentDetail>> listEquipmentDetailPage(
            @ApiParam(value = "当前页数", required = true, defaultValue = "1") @RequestParam Long currentPage,
            @ApiParam(value = "每页数据量", required = true, defaultValue = "10") @RequestParam Long pageSize,
            @ApiParam(value = "查询条件") EquipmentDetail equipmentDetail) {
        Page<EquipmentDetail> page = new Page<EquipmentDetail>(currentPage, pageSize);
        return R.success(equipmentDetailService.page(page, Wrappers.query(equipmentDetail).lambda().orderByDesc(EquipmentDetail::getCreateTime)),"分页信息查询成功");
    }


    /**
    * 通过id查询出入库管理表
    * @param id id
    * @return Result
    */
    @GetMapping("/getById")
    @ApiOperation(value = "通过id查询识别内容表", notes = "传入id")
    public R<EquipmentDetail> getEquipmentDetailById(@ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        return R.success(equipmentDetailService.getById(id));
    }

    /**
    * 新增出入库管理表
    * @param equipmentDetail 出入库管理表
    * @return Result
    */
    @PostMapping("/save")
    @ApiOperation(value = "新增识别内容表", notes = "传入EquipmentDetail数据")
    public R<Boolean> save(@RequestBody EquipmentDetailVO equipmentDetail) {
        EquipmentDetail equipmentDetail1 = new EquipmentDetail();
        BeanUtil.copyProperties(equipmentDetail, equipmentDetail1);
        Assert.isTrue(equipmentDetailService.save(equipmentDetail1), "操作失败");
        return R.success(true,"新增成功");
    }

    /**
    * 修改出入库管理表
    * @param equipmentDetail 出入库管理表
    * @return Result
    */
    @PostMapping("/updateById")
    @ApiOperation(value = "修改识别内容表", notes = "传入EquipmentDetail数据")
    public R<Boolean> updateById(@RequestBody EquipmentDetail equipmentDetail) {
        Assert.isTrue(equipmentDetailService.updateById(equipmentDetail), "修改失败");
        return R.success(true,"修改成功");
    }

    /**
    * 通过id删除出入库管理表
    * @param id id
    * @return Result
    */
    @GetMapping("/deleteById")
    @ApiOperation(value = "通过id删除识别内容表", notes = "传入id")
    public R<Boolean> deleteById(
            @ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        Assert.isTrue(equipmentDetailService.removeById(id), "操作失败");
        return R.success(true,"删除成功");
    }
}